
#include "rscentermgr.h"

CRsCenterMgr::CRsCenterMgr()
{
	m_pDBTreadMgr = NULL;
}
CRsCenterMgr::~CRsCenterMgr()
{
	RT_INFO_TRACE("CRsCenterMgr::~CRsCenterMgr");
}

RtResult CRsCenterMgr::Initialize(
					const char* strDBHost,
					const char* strDBName,
					const char* strUserName,
					const char* strPassword,
					WORD nThreadNumber,
					WORD nDbType)
{
	RtResult rv = RT_OK;
	if (NULL == m_pDBTreadMgr.Get())
	{
		m_pDBTreadMgr = new CDBThreadManager();
		RT_ASSERTE(m_pDBTreadMgr.Get());
	}
	rv = m_pDBTreadMgr->Initialize(
								strDBHost, 
								strDBName, 
								strUserName, 
								strPassword, 
								nThreadNumber, 
								TRUE, 	// DB thread AUTO select
								nDbType);
	return rv;
}

RtResult CRsCenterMgr::Initialize2(
					 const char* strDBHost,
					 unsigned short nPort,
					 const char* strDBName,
					 const char* strUserName,
					 const char* strPassword,
					 WORD nThreadNumber,
					 WORD nDbType)
{
	RtResult rv = RT_OK;
	if (NULL == m_pDBTreadMgr.Get())
	{
		m_pDBTreadMgr = new CDBThreadManager();
		RT_ASSERTE(m_pDBTreadMgr.Get());
	}
	rv = m_pDBTreadMgr->Initialize2(
								strDBHost, 
								nPort,
								strDBName, 
								strUserName, 
								strPassword, 
								nThreadNumber, 
								TRUE, 	// DB thread AUTO select
								nDbType);
	return rv;
}

RtResult CRsCenterMgr::FecthUserInfo(CRsRoomSink* pSink, int nNodeID, int nUsrID, const CRtString& strSession)
{
	RtResult rv = RT_OK;
	RT_ASSERTE(pSink);
	RT_INFO_TRACE("CRsCenterMgr::FecthUserInfo session:"<<strSession);
	
	s_UserInfo info;
	info.m_iNodeid = nNodeID;
	info.m_session = strSession;
	info.m_iUsrid = nUsrID;
	CFecthUserInfoEvent* pEvent = 
		new CFecthUserInfoEvent(pSink, info);
	
	RT_ASSERTE(pEvent && m_pDBTreadMgr);
	try{
		m_pDBTreadMgr->PostEvent(pEvent);
	}catch (...){
		RT_ERROR_TRACE_THIS("CRsCenterMgr::FecthUserInfo session:"<<strSession<<", execu catch error.");
	}
	return rv;
}

RtResult CRsCenterMgr::FecthRoomList(CRsRoomSink* pSink)
{
	RtResult rv = RT_OK;
	RT_ASSERTE(pSink);
	//RT_INFO_TRACE("CRsCenterMgr::FecthRoomList");
	
	CFecthRoomListEvent* pEvent = 
		new CFecthRoomListEvent(pSink);
	
	RT_ASSERTE(pEvent && m_pDBTreadMgr);
	try{
		m_pDBTreadMgr->PostEvent(pEvent);
	}catch (...){
		RT_ERROR_TRACE_THIS("CRsCenterMgr::FecthRoomList, execu catch error.");
	}
	return rv;
}

